package com.intelligentclass.services;

import com.intelligentclass.entity.Course;
import com.intelligentclass.repositories.CourseRespository;
import jakarta.persistence.EntityNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class CourseService {

    private CourseRespository courseRespository;

    public CourseService(CourseRespository courseRespository) {
        this.courseRespository = courseRespository;
    }

    public String getCnameByCno(String cno) {
        try{
            String cname = "";
            Course c = courseRespository.getReferenceById(cno);
            cname = c.getCname();
            return cname;
        }catch(EntityNotFoundException e){
            return null;
        }
    }
}
